package FileIO.stream;

import java.io.*;

public class useByteArrayOutputStream {
    public static void main(String[] args) throws IOException {
        InputStream input = new FileInputStream("src/main/data/hello.txt");
        try {
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int bytesRead = 0;
            while ((bytesRead = input.read(buf)) != -1) {
                output.write(buf, 0, bytesRead);
            }
            String data = output.toString("UTF-8");
            System.out.println(data);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            input.close();
        }
    }
}
